package net.dgg.zz.production.leadingInPorderOrder.service;


import net.dgg.iboss.base.service.CmsService;
import net.dgg.iboss.base.service.OrfApiService;
import net.dgg.iboss.base.service.UcApiService;
import net.dgg.iboss.base.util.DesUtil;
import net.dgg.iboss.base.util.JsonUtil;
import net.dgg.tmd.foundation.platform.common.util.TranslateUtil;
import net.dgg.tmd.foundation.platform.session.SessionManager;
import net.dgg.tmd.foundation.platform.user.service.UserService;
import net.dgg.zz.common.base.service.BaseService;
import net.dgg.zz.common.dao.OrderDao;
import net.dgg.zz.common.dao.ProductDao;
import net.dgg.zz.common.service.CommonMangerExtService;
import net.dgg.zz.common.service.CommonService;
import net.dgg.zz.common.service.OrderApiService;
import net.dgg.zz.common.systemRecord.service.SystemRecordService;
import net.dgg.zz.credential.baseCredential.dao.BaseCredentialDao;
import net.dgg.zz.credential.baseCredential.service.BaseCredentialService;
import net.dgg.zz.credential.certificateProduct.dao.CertificateProductDao;
import net.dgg.zz.credential.certificateProduct.service.CertificateProductService;
import net.dgg.zz.credential.certificateSpecialty.dao.CertificateSpecialtyDao;
import net.dgg.zz.credential.externalFunction.dao.ProductReservationDao;
import net.dgg.zz.credential.generalCredential.dao.GeneralCertificateDao;
import net.dgg.zz.credential.generalCredential.service.GeneralCredentialService;
import net.dgg.zz.credential.qualification.dao.QualificationDao;
import net.dgg.zz.credential.qualificationTransfer.dao.QualificationTransferDao;
import net.dgg.zz.credential.storageCapacity.dao.StorageCapacityDao;
import net.dgg.zz.credential.storageCapacity.service.StorageCapacityService;
import net.dgg.zz.credential.warningConfigure.service.SystemConfigureService;
import net.dgg.zz.production.inProcess.dao.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>@Title 办理中Service</p>
 * <p>@Description 办理中Service</p>
 * <p>@Version 1.0.0 版本号</p>
 * <p>@author maoquanyi</p>
 * <p>@date 2018年08月13日</p>
 * <p>Copyright © dgg group.All Rights Reserved. 版权信息</p>
 */
@Service
public class LeadingInProductOrderService extends BaseService {

    @Autowired
    private SessionManager sessionManager;
    @Autowired
    private CommonMangerExtService commonMangerExtService;
    @Autowired
    private UcApiService ucApiService;

    //新的引入
    @Autowired
    private ProductOrderDao productOrderDao;
    @Autowired
    private AssistantDao assistantDao;
    @Autowired
    private ProductNodeDao productNodeDao;
    @Autowired
    private FilesRecordDao filesRecordDao;
    @Autowired
    private ProductTimeStatusDao productTimeStatusDao;
    @Autowired
    private ProductNodeOperatingDao productNodeOperatingDao;
    @Autowired
    private ProductDataDao productDataDao;
    @Autowired
    private SystemRecordService systemRecordService;
    @Autowired
    private ProductDao productDao;
    @Resource
    private DesUtil desUtil;
    @Resource
    private TranslateUtil translateUtil;
    @Autowired
    private CmsService cmsService;
    @Resource
    private GeneralCredentialService generalCredentialService;
    @Resource
    private BaseCredentialService baseCredentialService;
    @Resource
    private StorageCapacityDao storageCapacityDao;
    @Resource
    private CertificateSpecialtyDao certificateSpecialtyDao;
    @Resource
    private StorageCapacityService storageCapacityService;
    @Resource
    private BaseCredentialDao baseCredentialDao;
    @Resource
    private CertificateProductService certificateProductService;//证书生产中间表操作
    @Resource
    private CertificateProductDao certificateProductDao;
    @Resource
    private ProductReservationDao productReservationDao;
    @Resource
    private CommonService commonService;
    @Autowired
    private GeneralCertificateDao generalCertificateDao;
    @Resource
    private SystemConfigureService systemConfigureService;
    @Resource
    private QualificationDao qualificationDao;
    @Resource
    private QualificationTransferDao qualificationTransferDao;
    @Resource
    private UserService userService;
    @Resource
    private OrfApiService orfApiService;

    @Resource
    private OrderApiService orderApiService;
    @Resource
    private OrderDao orderDao;


    @Transactional
    public void leadingInProductOrderZidong() throws Exception{
        Map param = new HashMap(){{put("productOrgId",70);}};//成都资质事业部
        List<Map> orderMapList = orderDao.selectOrderByLeadingIn(param);
        List<Map> productMapList = productDao.selectProductByLeadingIn(param);//子订单
        for (Map map : productMapList) {
            String orderId = map.get("orderId").toString();
            for (Map map2 : orderMapList) {//每个子订单循环来
                String orderId2 = map2.get("oId").toString();
                if (orderId.equals(orderId2)){
                    map.put("payStatus",map2.get("payStatus"));//往子订单里面设置收款状态
                    map2.put("contractNo",map.get("contractNo"));//往主订单里面设置合同编号
                    break;
                }
            }
        }
        List<Map>  productList = new ArrayList<>();
        if (orderMapList != null && !orderMapList.isEmpty()){
            for (Map map : orderMapList) {//每个子订单循环来
                String orderMap = JsonUtil.obj2Json(map);
                String orderId = map.get("oId").toString();
                for (Map map2 : productMapList) {
                    String orderId2 = map2.get("orderId").toString();
                    if (orderId.equals(orderId2)){//相等
                        productList.clear();
                        productList.add(map2);
                        String zzProdct = JsonUtil.obj2Json(productList);
                        orderApiService.insertOrder(orderMap,zzProdct);
                        break;
                    }
                }
            }
        }
    }

}
